using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_education : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else        
        {
            string educationID = Request.QueryString.Get("EducationID");  
            if(!IsPostBack  )
                EditEducation(educationID);
        }
    }

    void EditEducation(string educationID)
    {
        if (educationID != "" && educationID != null )
        {
            SQLServerProviders cls = new SQLServerProviders();
            DataTable dataTable =
            cls.GetDataTable("select * from tblJSEducations" +
            " where UserID='" + Session["jsuserid"] +
             "' and EducationID='" + educationID  
             + "'", CommandType.Text);
            EducationID.Value = dataTable.Rows[0][0].ToString();       
            txtSchool.Text = dataTable.Rows[0][2].ToString();
            ddlCountry.SelectedValue = dataTable.Rows[0][3].ToString();
            txtFaculty.Text = dataTable.Rows[0][4].ToString();
            txtMajor.Text =  dataTable.Rows[0][5].ToString()  ;
            txtCertificate.Text = dataTable.Rows[0][6].ToString();
            rblMode.SelectedValue = dataTable.Rows[0][7].ToString();
            txtFrom.Text=  dataTable.Rows[0][8].ToString();
            txtTo.Text= dataTable.Rows[0][9].ToString();
            txtDescription.Text = dataTable.Rows[0][10].ToString();
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(Session.Contents["jsuserid"]) != "")
            Response.Redirect("experiences.aspx");
        else
            Response.Redirect("experience.aspx");
    }
    protected void btnMore_Click(object sender, EventArgs e)
    {
        SQLServerProviders cls = new SQLServerProviders();
        if (!cls.AddNewUpdateEducation("0",
        Convert.ToString(Session.Contents["jsuserid"]),
        txtSchool.Text,
        ddlCountry.SelectedValue,
        txtFaculty.Text,
        txtMajor.Text, txtCertificate.Text,
        rblMode.SelectedValue,
        txtFrom.Text,txtTo.Text,txtDescription.Text))
            literalError.Text = "Error: " + cls.ErrorMessage;  
        else
            if(EducationID.Value!="")             
                Response.Redirect("educations.aspx");
            else
                Response.Redirect("education.aspx");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id="0";
        if(EducationID.Value!="") 
            id=EducationID.Value;
          
        SQLServerProviders cls = new SQLServerProviders();
        if (!cls.AddNewUpdateEducation(id,
        Convert.ToString(Session.Contents["jsuserid"]),
        txtSchool.Text,
        ddlCountry.SelectedValue,
        txtFaculty.Text,
        txtMajor.Text, txtCertificate.Text,
         rblMode.SelectedValue,
        txtFrom.Text, txtTo.Text, txtDescription.Text))
            literalError.Text = "Error: " + cls.ErrorMessage;
        else
            if (EducationID.Value != "")
                Response.Redirect("educations.aspx");
            else
                Response.Redirect("experience.aspx");
    }
}
